package cn.ywyself.controller;

import cn.ywyself.server.TextServer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/")
public class IndexController {

    private final Logger logger = LoggerFactory.getLogger(IndexController.class);

    @Resource
    TextServer textServer;

    @GetMapping("/")
    public String obj() {
        logger.info("打印日志测试");
        logger.error("打印日志测试");
        logger.warn("打印日志测试");
        logger.debug("打印日志测试");
        return "log";
    }

    @GetMapping("/log")
    public String index(@RequestParam String text) {
        if (textServer.append(text)) {
            return "ok";
        }
        return "fail";
    }
}
